/**
 * <p>Copyright @ 2009 深圳市金绎科技发展有限公司 </p>
 * <p>All right reserved. </p>
 * <p>项目名称				： 佛山市地方公路信息资源整合</p>
 * <p>JDK使用版本号		： jdk1.6.0_12 </P>
 * <p>描述						： 自定义标签,获得单位列表</p>
 * @version						： 1.0.0
 * @author						： created by 631wj
 *
 * <p>修改历史 </p>
 *
 * <p>修改时间     						修改人员             修改内容 </p>
 * <p> 2009-03-31                    								 新建   </p>
 */
package com.pengtu.web.taglib;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.pengtu.dao.QueryFilter;
import com.pengtu.entity.LabelValue;
import com.pengtu.entity.app.Department;
import com.pengtu.entity.app.ExternalOrganization;
import com.pengtu.entity.app.InsideOrganization;
import com.pengtu.entity.app.Organization;
import com.pengtu.entity.app.SuperviseGroup;
import com.pengtu.entity.app.User;
import com.pengtu.entity.asset.office.Information;
import com.pengtu.entity.project.OwnerOrganization;
import com.pengtu.entity.project.ProjectInfo;
import com.pengtu.entity.project.Qualification;
import com.pengtu.entity.project.SignUpContract;
import com.pengtu.service.app.AccountManager;
import com.pengtu.service.app.SuperviseManager;
import com.pengtu.service.asset.AssetsManager;
import com.pengtu.service.detect.DetectManager;
import com.pengtu.service.project.ProjectManager;
import com.pengtu.service.project.ProjectmassManager;
import com.pengtu.utils.DateUtils;

/**
 * Tag for creating multiple &lt;select&gt; options for displaying a list of
 * country names.
 * 
 * <p>
 * <b>NOTE</b> - This tag requires a Java2 (JDK 1.2 or later) platform.
 * </p>
 * 
 * @author Jens Fischer, Matt Raible
 * @version $Revision: 1.2 $ $Date: 2006-06-10 08:00:48 -0600 (Sat, 10 Jun
 *          2006) $
 * 
 * @jsp.tag name="country" bodycontent="empty"
 */
public class LabelsTag extends TagSupport {

	/**
	 * 获得前10年到后3年的年份列表
	 */
	private static final String YEAR_LIST = "year";

	/**
	 * 获得前10年到后3年的年份列表
	 */
	private static final String YEAR_NUMBER_LIST = "yearNum";

	/**
	 * 获得前月份的列表1- 12月
	 */
	private static final String MONTH_LIST = "month";

	/**
	 * 获得该部门Id下的所有部门
	 */
	private static final String DEPT_LIST = "dept";

	/**
	 * 获得单位集合
	 */
	private static final String ORG_LIST = "org";

	/**
	 * 获得施工合同段
	 */
	private static final String SIGN_LIST = "sign";
	/**
	 * 获得单位内部单位名称及下设的所有部门
	 */
	private static final String INSIDEORGDEPT_LIST = "insideOrgDept";

	private static final String PROJ_LIST = "proj";

	private static final String USER_LIST = "user";
	
	private static final String GRADE = "grade";
	
	private static final String CODE="code";
	/**
	 * 监督员
	 */
	private static final String SUPE_LIST = "supe";

	/**
	 * 获得单位工程下 的所有部门
	 */

	private static final String PROJ_DEPT = "projDept";
	/**
	 * 获取所有资产信息
	 */
	private static final String ASSETS = "assets";

	/**
	 * 获取所有批次
	 */
	private static final String BATCH = "batch";

	/***
	 * 获得所有的监督组
	 */

	private static final String SUPERVISE = "supervise";

	/**
	 * 根据用户ID得到用户名称
	 */
	private static final String USER = "userId";

	private static final String USER_NAME = "userName";

	private static final long serialVersionUID = 3905528206810167095L;
	/**
	 * 表单项的name
	 */
	private String name;
	/**
	 * labels type 指定不同的集合 需定义常量
	 */
	private String type;
	/**
	 * 若定义 scope （page session request application） 将labels放入内存中 name表示 对应的Key
	 */
	private String scope;
	/**
	 * 默认选中项
	 */
	private String selected;

	private String prompt;
	/**
	 * 是否包含一个为空的项
	 */
	private boolean hasEmpty = true;
	/**
	 * select 表单的宽度
	 */
	private int width;
	/**
	 * 是否根据键获得对应的唯一的值
	 */
	private boolean single;

	/**
	 * 预留参数1
	 */
	private String argument1;
	/**
	 * 预留参数2
	 */
	private String argument2;
	/**
	 * 预留参数3
	 */
	private String argument3;

	/**
	 * Process the start of this tag.
	 * 
	 * @return int status
	 * 
	 * @exception JspException
	 *                if a JSP exception has occurred
	 * 
	 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
	 */
	public int doStartTag() throws JspException {

		List<LabelValue> lists = new ArrayList<LabelValue>();
		if ((YEAR_LIST).equals(type)) {
			// 获得年份的列表
			lists = this.buildYearsList();
		} else if ((YEAR_NUMBER_LIST).equals(type)) {
			// 获得年份的列表
			lists = this.buildYearNumbersList();
		} else if ((MONTH_LIST).equals(type)) {
			// 获得月份的列表
			lists = this.buildMonthsList();
		} else if ((DEPT_LIST).equals(type)) {
			if (isSingle()) {
				String deptName = "";
				if (StringUtils.isNotEmpty(argument2)) {
					if (StringUtils.equals("orgName", argument2)) {
						deptName = this.getOrgName();
					}
				} else {
					deptName = this.getDeptName();
				}
				try {
					pageContext.getOut().write(deptName);
				} catch (IOException e) {
					throw new JspException(e);
				}
				return super.doStartTag();
			}
			lists = this.getDeptList();
		} else if ((ORG_LIST).equals(type)) {
			if (isSingle()) {
				String orgName = this.getOrgById();
				try {
					pageContext.getOut().write(orgName);
				} catch (IOException e) {
					throw new JspException(e);
				}
				return super.doStartTag();
			}
			lists = this.getOrgList();
		} else if ((SIGN_LIST).equals(type)) {
			if (isSingle()) {
				String sigName = this.getSign();
				try {
					pageContext.getOut().write(sigName);
				} catch (IOException e) {
					throw new JspException(e);
				}
				return super.doStartTag();
			}
			// 获得施工合同段
			lists = this.getSignUpContract();
		} else if ((PROJ_LIST).equals(type)) {
			if (isSingle()) {
				String projName = this.getProject();
				try {
					pageContext.getOut().write(projName);
				} catch (IOException e) {
					throw new JspException(e);
				}
				return super.doStartTag();
			}
		} else if ((USER_LIST).equals(type)) {
			if (isSingle()) {
				String name = this.getNameByUserName();
				try {
					pageContext.getOut().write(name);
				} catch (IOException e) {
					throw new JspException(e);
				}
				return super.doStartTag();
			}
			lists = this.getuserNameByRoleName();
		} else if ((SUPERVISE).equals(type)) {
			if (isSingle()) {
				String name = this.getNameByUserName();
				try {
					pageContext.getOut().write(name);
				} catch (IOException e) {
					throw new JspException(e);
				}
				return super.doStartTag();
			}
			lists = this.getAllSupervise();
		} else if ((USER_NAME).equals(type)) {
			if (isSingle()) {
				String username = this.getUserNameById();
				try {
					pageContext.getOut().write(username);
				} catch (IOException e) {
					throw new JspException(e);
				}
				return super.doStartTag();
			}
		} else if ((GRADE).equals(type)) {
			if (isSingle()) {
				String username = this.getQualifsByOrgId();
				try {
					pageContext.getOut().write(username);
				} catch (IOException e) {
					throw new JspException(e);
				}
				return super.doStartTag();
			}
		} else if ((CODE).equals(type)) {
			if (isSingle()) {
				String username = this.getQualifsByOrgId();
				try {
					pageContext.getOut().write(username);
				} catch (IOException e) {
					throw new JspException(e);
				}
				return super.doStartTag();
				}
		} else if ((INSIDEORGDEPT_LIST).equals(type)) {
			lists = this.getInsideOrg_dept();
		} else if ((PROJ_DEPT).equals(type)) {
			lists = this.getprojDept();
		} else if ((ASSETS).equals(type)) {
			lists = this.getAssets();
		} else if ((BATCH).equals(type)) {
			lists = this.getBatch();
		} else if ((USER).equals(type)) {
			if (isSingle()) {
				String userName = this.getUserNameByUserId();
				try {
					pageContext.getOut().write(userName);
				} catch (IOException e) {
					throw new JspException(e);
				}
				return super.doStartTag();
			}
		} else {
			LabelValue label = new LabelValue("没有值", "");
			lists.add(label);
		}
		if (scope != null) {
			if (scope.equals("page")) {
				pageContext.setAttribute(name, lists);
			} else if (scope.equals("request")) {
				pageContext.getRequest().setAttribute(name, lists);
			} else if (scope.equals("session")) {
				pageContext.getSession().setAttribute(name, lists);
			} else if (scope.equals("application")) {
				pageContext.getServletContext().setAttribute(name, lists);
			} else {
				throw new JspException(
						"Attribute 'scope' must be: page, request, session or application");
			}
		} else {
			StringBuilder sb = new StringBuilder();
			sb.append("<select name=\"" + name + "\" id=\"" + name
					+ "\" class=\"select\" "
					+ (width == 0 ? "" : "style=\"width: " + width + "px\"")
					+ " >\n");
			if (prompt == null && this.hasEmpty) {
				sb.append("<option value=\"\"> </option>");
			} else if (prompt != null) {
				sb.append("    <option value=\"\" >");
				sb.append(prompt);
				sb.append("</option>\n");
			}
			for (Iterator<LabelValue> i = lists.iterator(); i.hasNext();) {
				LabelValue labelValue = i.next();
				if ("optgroup".equals(labelValue.getValue())) {
					sb.append("<optgroup label=" + labelValue.getLabel() + ">");
				} else {
					sb.append("<option value=\"" + labelValue.getValue() + "\"");
					if ((selected != null)
							&& selected.equals(labelValue.getValue())) {
						sb.append(" selected=\"selected\"");
					}
					sb.append(">" + labelValue.getLabel() + "</option>\n");
				}
			}
			sb.append("</select>");

			try {
				pageContext.getOut().write(sb.toString());
			} catch (IOException io) {
				throw new JspException(io);
			}
		}

		return super.doStartTag();
	}

	/**
	 * 查询所有监督组
	 * 
	 * @return
	 */
	private List<LabelValue> getAllSupervise() {
		// TODO Auto-generated method stub
		SuperviseManager superviseManager = (SuperviseManager) this
				.getBean("superviseManager");

		List<SuperviseGroup> supervises = superviseManager.findAllSe();
		List<LabelValue> units = new ArrayList<LabelValue>();
		for (SuperviseGroup supervise : supervises) {
			// 保存单位名称
			LabelValue orglabelValue = new LabelValue(supervise.getName(),
					supervise.getId());
			units.add(orglabelValue);
		}
		return units;
	}

	/**
	 * 获取所有资产信息 getAssets: 适用:添加资产记录
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public List<LabelValue> getAssets() {
		AssetsManager assetsManager = (AssetsManager) this
				.getBean("assetsManager");
		// 找出所有内部单位
		List<Information> assetList = assetsManager.getAllInformation();
		List<LabelValue> units = new ArrayList<LabelValue>();
		for (Information asset : assetList) {
			// 保存单位名称
			LabelValue orglabelValue = new LabelValue(asset.getName(),
					asset.getId());
			units.add(orglabelValue);
		}
		return units;
	}

	public List<LabelValue> getBatch() {
		DetectManager detectManager = (DetectManager) this
				.getBean("detectManager");
		List<LabelValue> units = new ArrayList<LabelValue>();
		List<String> batchList = detectManager.getSpotreportBatch(argument1,
				argument2, argument3);
		for (String batch : batchList) {
			LabelValue labelValue = new LabelValue(batch, batch);
			units.add(labelValue);
		}
		return units;
	}

	/**
	 * 
	 * getInsideOrg_dept: 适用:获得内部单位下的部门列表及单位名称
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	private List<LabelValue> getInsideOrg_dept() {
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");
		// 找出所有内部单位
		List<InsideOrganization> insideList = accountManager
				.getInsideOrganization();
		// 找出单位下的所有部门
		List<Department> deptList = new ArrayList<Department>();

		List<LabelValue> units = new ArrayList<LabelValue>();
		for (InsideOrganization insideOrganization : insideList) {
			// 保存单位名称
			LabelValue orglabelValue = new LabelValue(
					insideOrganization.getOrgName(), "optgroup");
			units.add(orglabelValue);
			// 获得单位下的部门集合
			deptList = accountManager.findDeptList("organization.id",
					insideOrganization.getId());
			for (Department dept : deptList) {
				// 保存部门
				if (null != argument1) {
					LabelValue deptlabelValue = new LabelValue(
							dept.getDepName(), dept.getDepName());
					units.add(deptlabelValue);
				} else {
					LabelValue deptlabelValue = new LabelValue(
							dept.getDepName(), dept.getId());
					units.add(deptlabelValue);
				}
			}
		}
		return units;
	}

	/**
	 * 获得当前父部门下的部门列表 人员情况添加
	 * 
	 * @return
	 */
	protected List<LabelValue> getDeptList() {
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");
		List<Department> deptList = new ArrayList<Department>();
		List<LabelValue> units = new ArrayList<LabelValue>();
		if ("1".equals(argument2)) {
			deptList = accountManager
					.findDeptList("organization.id", argument1);
		} else {
			deptList = accountManager.findDeptList("fid", argument1);
			
			Department fdept = accountManager.findByDepartment("id", argument1);
			LabelValue flableValue = new LabelValue("--"+fdept.getDepName(),
					fdept.getId());
			units.add(flableValue);
		}
		
		for (Department dept : deptList) {
			
			LabelValue lableValue = new LabelValue("----"+dept.getDepName(),
					dept.getId());
			
			units.add(lableValue);
		}
		return units;
	}

	/**
	 * 根据id查部门名称 getDeptName: 适用:
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public String getDeptName() {
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");
		if (StringUtils.isEmpty(argument1)) {
			return null;
		} else {
			return accountManager.getDepartment(argument1).getDepName();
		}
	}

	/**
	 * getInsideOrgList: 适用:查找所有单位信息
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	protected List<LabelValue> getOrgList() {
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");
		List<InsideOrganization> insideOrgList = new ArrayList<InsideOrganization>();
		List<ExternalOrganization> exterOrgList = new ArrayList<ExternalOrganization>();
		List<LabelValue> units = new ArrayList<LabelValue>();
		if ("inside".equals(argument1)) {
			insideOrgList = accountManager.getInsideOrganization();
			for (InsideOrganization insideOrg : insideOrgList) {
				LabelValue labelValue = new LabelValue(insideOrg.getOrgName(),
						insideOrg.getId());
				units.add(labelValue);
			}
		} else if ("exter".equals(argument1)) {
			exterOrgList = accountManager.getExternalOrganization();
			for (ExternalOrganization exterOrg : exterOrgList) {
				LabelValue labelValue = new LabelValue(exterOrg.getOrgName(),
						exterOrg.getId());
				units.add(labelValue);
			}
		}
		return units;
	}

	/**
	 * 
	 * getprojDept: 适用:获得单位工程下的所有部门
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public List<LabelValue> getprojDept() {
		ProjectManager projectManager = (ProjectManager) this
				.getBean("projectManager");
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");

		// 声明部门集合
		List<Department> deptList = new ArrayList<Department>();
		List<LabelValue> units = new ArrayList<LabelValue>();

		// 获得单位工程信息
		ProjectInfo projectInfo = projectManager.getProj("id", argument1);

		// 添加建设单位
		if (StringUtils.isEmpty(argument2) || "1".equals(argument2)) {
			OwnerOrganization ownerOrg = projectInfo.getOrgCode();
			if (null != ownerOrg) {
				LabelValue ownerorglabelValue = new LabelValue(
						ownerOrg.getOrgName(), "optgroup");
				units.add(ownerorglabelValue);
				// 查出建设单位下的所有部门
				List<Department> ownerDeptList = accountManager.findDeptList(
						"organization.id", ownerOrg.getId());
				for (Department department : ownerDeptList) {
					LabelValue deptlabelValue = new LabelValue(
							department.getDepName(), department.getId());
					units.add(deptlabelValue);
				}
			}
		}

		// 获得单位工程下的所有合同段信息
		QueryFilter queryFilter = new QueryFilter();
		List<SignUpContract> signUpContractList = new ArrayList<SignUpContract>();

		if (StringUtils.isNotEmpty(argument2)) {
			if (StringUtils.equals("2", argument2)) {
				queryFilter.addFilter("contractKind", argument2);
				queryFilter.addFilter("projectId", argument1);
				signUpContractList = projectManager.findPageSign(queryFilter);

			} else if (StringUtils.equals("3", argument2)) {
				queryFilter.addFilter("contractKind", argument2);
				queryFilter.addFilter("projectId", argument1);
				signUpContractList = projectManager.findPageSign(queryFilter);

			} else if (StringUtils.equals("4", argument2)) {
				queryFilter.addFilter("contractKind", argument2);
				queryFilter.addFilter("projectId", argument1);
				signUpContractList = projectManager.findPageSign(queryFilter);
			}
		} else {
			signUpContractList = projectManager.findSignList("projectId",
					argument1);
		}

		for (SignUpContract signUpContract : signUpContractList) {
			// 机构ID
			String deptId = signUpContract.getBranchOrgCode().getId();
			LabelValue fdeptlabelValue = new LabelValue(signUpContract
					.getBranchOrgCode().getDepName(), "optgroup");
			units.add(fdeptlabelValue);
			deptList = accountManager.findDeptList("fid", deptId);

			for (Department dept : deptList) {
				LabelValue deptlabelValue = new LabelValue(dept.getDepName(),
						dept.getId());
				units.add(deptlabelValue);
			}
		}
		return units;
	}

	public String getOrgById() {
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");
		String orgName = null;
		if (StringUtils.isEmpty(argument1)) {
			orgName = null;
		} else {
			try {
				Organization organization = accountManager
						.getOrganization(argument1);
				if (organization != null) {
					orgName = organization.getOrgName();
				}
			} catch (Exception e) {
				;
			}
		}
		return orgName;
	}

	/**
	 * 查询施工合同段 getSignUpContract: 适用:
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	protected List<LabelValue> getSignUpContract() {
		ProjectManager projectManager = (ProjectManager) this
				.getBean("projectManager");
		List<SignUpContract> signUpContractList = new ArrayList<SignUpContract>();
		if ("4".equals(argument2)) {
			signUpContractList = projectManager.getSignUpContracts(argument1,
					argument2);
			System.out.println(signUpContractList.size());
		} else {
			signUpContractList = projectManager.getSignUpContracts(argument1);
		}
		List<LabelValue> units = new ArrayList<LabelValue>();
		for (SignUpContract signUpContract : signUpContractList) {
			LabelValue lableValue = new LabelValue(
					signUpContract.getContractOrder(), signUpContract.getId());
			units.add(lableValue);
		}
		return units;
	}


	/**
	 * 查询合同段名称 getSign: 适用:
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public String getSign() {
		ProjectManager projectManager = (ProjectManager) this
				.getBean("projectManager");
		if (StringUtils.isEmpty(argument1)) {
			return null;
		} else {
			SignUpContract signUpContract = projectManager.getSign("id",
					argument1);
			return signUpContract.getContractOrder();
		}
	}
	
	/**
	 * 适用于根据部门Id查询grade 
	 * @return
	 */
	public String getQualifsByOrgId() {
		ProjectmassManager projectmassManager = (ProjectmassManager) this
				.getBean("projectmassManager");
		if (StringUtils.isEmpty(argument1)) {
			return null;
		} else {
			Qualification qualification=projectmassManager.getQualificationByorgId(argument1);
			if(qualification==null){
				return null;
			}else{
				return qualification.getGrade();
			}
			
		}
	}
	/**
	 * 适用根据部门Id查询code
	 * @return
	 */
	public String getQualifsByCode(){
		ProjectmassManager projectmassManager=(ProjectmassManager)this.getBean("projectmassManager");
		if(StringUtils.isNotEmpty(argument1)){
			return null;
		}else{
			Qualification qualification=projectmassManager.getQualificationByorgId(argument1);
			if(qualification==null){
				return null;
			}else{
				return qualification.getCode();
			}
		}
	}

	/**
	 * 查询项目名称 getProject: 适用:
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public String getProject() {
		ProjectManager projectManager = (ProjectManager) this
				.getBean("projectManager");
		String projName = null;
		if (StringUtils.isEmpty(argument1)) {
			projName = null;
		} else {
			ProjectInfo projectInfo = projectManager.getProj("id", argument1);
			if (projectInfo == null) {
				projName = null;
			} else {
				projName = projectInfo.getProjName();
			}
		}
		return projName;
	}

	/**
	 * Release aquired resources to enable tag reusage.
	 * 
	 * @see javax.servlet.jsp.tagext.Tag#release()
	 */
	public void release() {
		super.release();
	}

	/**
	 * Spring 管理bean
	 * 
	 * @param name
	 * @return
	 */
	public Object getBean(String name) {
		ApplicationContext ctx = WebApplicationContextUtils
				.getRequiredWebApplicationContext(this.pageContext
						.getServletContext());
		return ctx.getBean(name);
	}

	/**
	 * 获得年份的列表
	 * 
	 * @return
	 * 
	 *         631wj List
	 */
	protected List<LabelValue> buildYearsList() {
		List<LabelValue> units = new ArrayList<LabelValue>();
		int currentYear = DateUtils.getCurrentYear();
		for (int i = currentYear - 5; i < currentYear + 3; i++) {
			LabelValue label = new LabelValue(i + "年", i + "年");
			units.add(label);
		}
		return units;
	}

	/**
	 * 获得年份的列表
	 * 
	 * @return
	 * 
	 *         631wj List
	 */
	protected List<LabelValue> buildYearNumbersList() {
		List<LabelValue> units = new ArrayList<LabelValue>();
		int currentYear = DateUtils.getCurrentYear();
		for (int i = currentYear - 5; i < currentYear + 3; i++) {
			LabelValue label = new LabelValue(i + "年", i + "");
			units.add(label);
		}

		return units;

	}

	/**
	 * 获得月份的列表
	 * 
	 * @return
	 * 
	 *         631wj List
	 */
	protected List<LabelValue> buildMonthsList() {
		List<LabelValue> units = new ArrayList<LabelValue>();
		for (int i = 1; i < 13; i++) {
			LabelValue label = null;
			if (i < 10) {
				label = new LabelValue("0" + i + "月", "0" + i + "");
			} else {
				label = new LabelValue(i + "月", i + "");
			}
			units.add(label);
		}

		return units;

	}

	private String getOrgName() {
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");
		if (StringUtils.isEmpty(argument1)) {
			return null;
		} else {
			return accountManager.getDepartment(argument1).getOrganization()
					.getOrgName();
		}
	}

	/**
	 * 根据传入的用户名查询姓名 getUserName: 适用:
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	private String getNameByUserName() {
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");
		if (StringUtils.isEmpty(argument1)) {
			return null;
		} else {
			User user = accountManager.getNameByUserName(argument1);
			if (null == user) {
				return null;
			} else {
				return user.getName();
			}
		}
	}

	private String getUserNameById() {
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");
		if (StringUtils.isEmpty(argument1)) {
			return null;
		} else {
			User user = accountManager.getUser(argument1);
			if (null == user) {
				return null;
			} else {
				return user.getUserName();
			}
		}
	}

	/**
	 * 根据roleName查询用户 getuserNameByRoleName: 适用:
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	private List<LabelValue> getuserNameByRoleName() {
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");
		List<LabelValue> units = new ArrayList<LabelValue>();
		List<User> users = accountManager.getUserByRoleId(argument1);
		for (User user : users) {
			LabelValue lableValue = new LabelValue(user.getName(),
					user.getUserName());
			units.add(lableValue);
		}
		return units;
	}

	private String getUserNameByUserId() {
		AccountManager accountManager = (AccountManager) this
				.getBean("accountManager");
		if (StringUtils.isEmpty(argument1)) {
			return null;
		} else {
			User user = accountManager.getUser(argument1);
			if (null == user) {
				return null;
			} else {
				return user.getName();
			}
		}
	}

	/**
	 * @param name
	 *            The name to set.
	 * 
	 * @jsp.attribute required="false" rtexprvalue="true"
	 */
	public void setName(String name) {
		this.name = name;
	}

	public String getArgument1() {
		return argument1;
	}

	/**
	 * @param selected
	 *            The selected option.
	 * @jsp.attribute required="false" rtexprvalue="true"
	 */
	public void setDefault(String selected) {
		this.selected = selected;
	}

	/**
	 * Property used to simply stuff the list of countries into a specified
	 * scope.
	 * 
	 * @param scope
	 * 
	 * @jsp.attribute required="false" rtexprvalue="true"
	 */
	public void setToScope(String scope) {
		this.scope = scope;
	}

	/**
	 * list 类别 可能是 管养单位(manager), 观测站(station),
	 * 
	 * @param type
	 * @jsp.attribute required="true" rtexprvalue="true"
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * 查询参数1
	 * 
	 * @param argument1
	 */
	public void setArgument1(String argument1) {
		this.argument1 = argument1;
	}

	/**
	 * 查询参数2
	 * 
	 * @param argument1
	 */
	public void setArgument2(String argument2) {
		this.argument2 = argument2;
	}

	public String getArgument2() {
		return argument2;
	}

	public String getArgument3() {
		return argument3;
	}

	public void setArgument3(String argument3) {
		this.argument3 = argument3;
	}

	public boolean isSingle() {
		return single;
	}

	public void setSingle(boolean single) {
		this.single = single;
	}

	public boolean isHasEmpty() {
		return hasEmpty;
	}

	public void setHasEmpty(boolean hasEmpty) {
		this.hasEmpty = hasEmpty;
	}

	public void setPrompt(String prompt) {
		this.prompt = prompt;
	}

	public void setWidth(int width) {
		this.width = width;
	}

}
